import { request } from '@umijs/max';

// 分页查询存款产品列表
export async function getDepositPage(params: {
  page?: number;
  size?: number;
  depositName?: string;
  startTime?: string;
  endTime?: string;
}, options?: { [key: string]: any }) {
  console.log('Debug - depositController getDepositPage params:', params);
  try {
    const response = await request('/api/admin/deposits/page', {
      method: 'GET',
      params,
      ...(options || {}),
    });
    console.log('Debug - depositController getDepositPage response:', response);
    return response;
  } catch (error) {
    console.error('Debug - depositController getDepositPage error:', error);
    throw error;
  }
}

// 根据ID查询存款产品
export async function getDepositById(depositId: number, options?: { [key: string]: any }) {
  return request(`/api/admin/deposits/${depositId}`, {
    method: 'GET',
    ...(options || {}),
  });
}

// 获取存款产品列表（兼容旧接口）
export async function getDepositList(params?: any, options?: { [key: string]: any }) {
  return request('/api/admin/deposits', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 创建存款产品
export async function createDeposit(body: {
  depositName: string;
  description: string;
  termYears?: number;
}, options?: { [key: string]: any }) {
  return request('/api/admin/deposits', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

// 更新存款产品
export async function updateDeposit(body: {
  depositId: number;
  depositName: string;
  description: string;
  termYears?: number;
}, options?: { [key: string]: any }) {
  return request(`/api/admin/deposits/${body.depositId}`, {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
}

// 删除存款产品
export async function deleteDeposit(depositId: number, options?: { [key: string]: any }) {
  return request(`/api/admin/deposits/${depositId}`, {
    method: 'DELETE',
    ...(options || {}),
  });
} 